<#assign title='New User'/>
<#include "/frag.dialog-head.ftl">
<form id="theform" class="form-horizontal" style="padding-top: 10px;">
  <input type="hidden" name="user_agent_id" value=""/>
  <div class="form-group">
    <label for="login_name" class="col-md-3 control-label">loginName</label>
    <div class="col-md-9">
      <input type="text" class="form-control" id="login_name" name="login_name">
    </div>
  </div>
  <div class="form-group">
    <label for="login_password" class="col-md-3 control-label">loginPassword</label>
    <div class="col-md-9">
      <input type="password" class="form-control" name="login_password">
    </div>
  </div>
  <div class="form-group">
    <label for="real_name" class="col-md-3 control-label">realName</label>
    <div class="col-md-9">
      <input type="text" class="form-control" name="real_name">
    </div>
  </div>
  <div class="form-group">
    <label for="mobile" class="col-md-3 control-label">mobile</label>
    <div class="col-md-9">
      <input type="number" class="form-control" id="mobile" name="mobile">
    </div>
  </div>
  <div class="form-group">
    <label for="email" class="col-md-3 control-label">Email</label>
    <div class="col-md-9">
      <input type="email" class="form-control" id="email" name="email">
    </div>
  </div>

</form>
<#include "/frag.dialog-foot.ftl">
<script src="${s0('/jquery-validation/validate-methods.js')}"></script>
<script>
  $(function () {

    $("#theform").validate({
      rules: {
        login_name: {
          required: true,
          maxlength: 50,
          minlength: 2,
          remote: {
            url: "/user/check_name.json",
            type: "post",
            data: {
              login_name: function () {
                return $("#login_name").val();
              }
            }
          }
        },
        login_password: {
          required: true,
          maxlength: 20,
          minlength: 3
        },
        real_name: {
          required: false,
          isChinese: true,
          maxlength: 10,
          minlength: 2
        },
        mobile: {
          isMobile: true
        },
        email: {
          email: true
        }
      },
      messages: {
        login_name: {
          required: "登陆名不能为空！",
          remote: "用户名已经被注册"
        }
      },

      submitHandler: function (form) {
        // 校验完成
        var d = getFormJson(form);
        var loadingLayerHandler;
        $.ajax({
          url: '/users/modify.json',
          type: "post",
          data: JSON.stringify(d),
          dataType: "json",
          contentType: "application/json; charset=utf-8",
          beforeSend: function () {
            loadingLayerHandler = top.layer.msg('正在保存', {
              icon: 16,
              shade: 0.5,
              scrollbar: false,
              zIndex: top.layer.zIndex,
              anim: 0
            });
          },
          success: function (data) {
            top.layer.close(loadingLayerHandler);
            if (!data.success) {
              top.layer.open({title: '错误', content: data.msg, shadeClose: true, anim: 0});
              return;
            }
            top.layer.msg("操作成功", {zIndex: top.layer.zIndex});
            closeWindow();
          },
          error: function (e) {
            top.layer.close(loadingLayerHandler);
            top.layer.open({
              title: '保存时发生错误',
              content: JSON.stringify(e),
              shadeClose: true,
              zIndex: top.layer.zIndex,
              anim: 0
            });
          }
        });
      }

    });
  });


  function save(cb) {
    $("#theform").submit();
  }

</script>